/***************
 * Organization Children Panel
 */
AIR2.Organization.Children = function() {
    var p = new AIR2.UI.Panel({
        colspan: 1,
        title: 'Child Organizations',
        showTotal: true,
        iconCls: 'air2-icon-organization',
        tools: ['->', {
            xtype: 'air2button',
            air2type: 'CLEAR',
            iconCls: 'air2-icon-add',
            tooltip: 'New Child Organization',
            hidden: !AIR2.Organization.ORGDATA.authz.may_manage,
            handler: function() {
                AIR2.Organization.Create({
                    originEl: p.el,
                    parentUUID: AIR2.Organization.ORGUUID,
                    callback: function(success, msg) {
                        if (success) p.reload();
                    }
                });
            }
        }],
        storeData: AIR2.Organization.CHDDATA,
        url: AIR2.Organization.ORGURL + '/children',
        itemSelector: '.air2-org-child',
        tpl: new Ext.XTemplate(
            '<table><tpl for=".">' +
              '<tr class="air2-org-child">' +
                '<td>{[AIR2.Format.orgNameLong(values, "name")]}</td>' +
                '<td align="right">{[AIR2.Format.date(values.org_upd_dtim)]}</td>' +
                '<td align="right">{[AIR2.Format.date(values.org_cre_dtim)]}</td>' +
              '</tr>' +
            '</tpl></table>',
            {compiled: true, disableFormats: true}
        ),
        editModal: {
            allowAdd: false,
            width: 450,
            items: {
                xtype: 'air2liveeditor',
                url: AIR2.Organization.ORGURL + '/children',
                sortField: 'org_display_name',
                sortDir: 'ASC',
                pageSize: 50,
                hideButtons: true,
                tpl: new Ext.XTemplate(
                    '<table><tr class="air2-org-child">' +
                      '<td>{[AIR2.Format.orgNameLong(values, "name")]}</td>' +
                      '<td align="right">{[AIR2.Format.dateLong(values.org_upd_dtim)]}</td>' +
                      '<td align="right">{[AIR2.Format.dateLong(values.org_cre_dtim)]}</td>' +
                    '</tr></table>',
                    {compiled: true, disableFormats: true}
                )
            }
        }
    });
    return p;
}
